import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class FileInputReader {
	public static Object[] getTableFrom(File f) throws FileNotFoundException{
		Scanner sc = new Scanner(f);
		int inputs = sc.nextInt();
		int states = sc.nextInt();
		
		Pattern pattern = Pattern.compile("([A-Z])/([0-1])");
		Matcher matcher;
		TransitionTable t = new TransitionTable(inputs);
		State[] row;
		String line;
		String[] data;
		//TODO check for duplicates
		for(int i=0; i<states; i++){
			line = sc.next();
			data = line.split(";");
			row = new State[inputs+1];
			row[0] = new State(data[0].toUpperCase());
			for(int j=1; j<=inputs; j++){
				matcher = pattern.matcher(data[j].toUpperCase());
				if(matcher.find()){
					row[j] = new State(matcher.group(1),Integer.parseInt(matcher.group(2)));
				}
			}
			t.addRow(row);
		}
		return new Object[]{t,new Integer(states), new Integer(inputs)};
	}
}
